const mongoose = require('mongoose')
mongoose.connect('mongodb://songyuening:123456@localhost:27017/projectData', {useNewUrlParser: true, useUnifiedTopology: true})
		.then(() => {
			console.log('数据库创建成功')
		}).catch(err => console.log(err))
const userSchema = new mongoose.Schema({
	username: {
		type: String,
		required: true,
		message: '请输入账号',
		min: 6,
		trim: true,
		max: 15
	},
	password: {
		type: String,
		required: true,
		trim: true,
		min: 6,
		max: 15,
		message: '请输入密码'
	}
})
const articleSchema = new mongoose.Schema({
	serialNumber: {
		type: Number,
		required: true,
		trim: true,
		unique: true
	},
	date: {
		type: Date,
		default: Date.now()
	},
	title: {
		type: String,
		required: true,
		min: 10,
		trim: true
	},
	country: {
		type: String,
		default: 'China'
	},
	author: {
		type: String,
		required: true,
		default: 'editor',
		trim: true
	},
	importance: {
		type: Number,
		min: 1,
		max: 3
	},
	readings: {
		type: Number
	},
	status: {
		type: Number,
		default: 0
	},
	audit: {
		type: String,
		default: 'Admin'
	}
})
const createArticleSchema = new mongoose.Schema({
	serialNumber: {
		type: Number,
		required: true,
		trim: true,
		unique: true
	},
	date: {
		type: Date,
		default: Date.now()
	},
	title: {
		type: String,
		required: true,
		min: 10,
		trim: true
	},
	country: {
		type: String,
		default: 'China'
	},
	author: {
		type: String,
		required: true,
		default: 'editor',
		trim: true
	},
	importance: {
		type: Number,
		min: 1,
		max: 3
	},
	readings: {
		type: Number
	},
	status: {
		type: Number,
		default: 0
	},
	audit: {
		type: String,
		default: 'Admin'
	},
	platforms: [String],
	command: {
		type: Number,
		default: 1
	},
	link: {
		type: String
	},
	summary: {
		type: String,
		require: [true, '缺少文章摘要']
	},
	content: {
		type: String,
		require: [true, '缺少文章主体内容']
	}
})
const User = new mongoose.model('User', userSchema)
const Article = new mongoose.model('Article', articleSchema)
const CreateArticle = new mongoose.model('CreateArticle', createArticleSchema)
module.exports = {
	User,
	Article,
	CreateArticle
}